|
|
|
|
|
|
|
You can prevent this sort of problem by adding a distance term to the shading model. In the real world, light intensity decreases proportionally to the square of the distance to the light source. Adding a term that decreases with the distance squared does not work well in practice, however. If you try to place the light source infinitely far away, you will have trouble dividing by the square of an infinite number. Even if the light source is not infinitely far away, it is often relatively far away compared with the distances between the objects. In that case, the differences in light intensity between different objects are very small. |
|
|
|
|
|
|
|
|
A solution that works well in practice is to make the light intensity Id at an object proportional to 1/(r + kdist) where kdist is a constant and r is the distance from the object to the light source. When this correction is added, the shading model becomes: |
|
|
|
 |
|
|
|
|
I = Ia * ka + Ii * kd * (L . N) / (r + kdist) |
|
|
|
|
|
|
|
|
If you add this term and make no other correction, the overall brightness of your image is greatly reduced. Because you are dividing the term representing diffuse reflection by a large number, particularly if the light source is far from the polygons so that r is large, the image is much darker. |
|
|
|
|
|
|
|
|
To prevent this, you can increase the intensity of the light source Ii. If rmin is the smallest distance from any polygon to the light source, you can adjust Ii by a factor of (rmin + kdist). Then the intensity at polygons closest to the light source is roughly the same as it would be without the distance term. The intensity at polygons farther away is reduced. Adding this scaling term to the lighting equation gives: |
|
|
|
 |
|
|
|
|
I = Ia * ka + Ii * kd * (L · N) * (rmin + kdist) / (r + kdist) |
|
|
|
|
|
|
|
|
Figure 16.4
Parallel faces are the same color with diffuse and ambient lighting. |
|
|
|
|
|